<template>
  <div>
    <Header :title="title"></Header>
    <div v-if="invite.finished && invite.items.length == 0" v-cloak>
        <div class="no-data aui-text-center aui-text-9">
            <i class="iconfont icon-lujing1161"></i>
            <div class="aui-ftn16">
                空空如也~
            </div>
        </div>
    </div>
    <div class="record aui-bg-f">
		<van-pull-refresh v-model="invite.refreshing" @refresh="fnLoadMore" :disabled="disabled">
		    <van-list
		      v-model="invite.loading"
		      :finished="invite.finished"
		      :finished-text="text"
		      @load="onLoadData"
		    >
		        <van-row class="list aui-text-7 aui-ftn14 van-hairline--bottom" v-for="(item, index) in invite.items" :key="index">
		            <van-col span="18" class="lt">
		                <div class="name aui-ftn15 aui-text-3 aui-font-weight" v-text="item.type"></div>
		                <div class="time aui-text-7 aui-ftn12" v-text="item.createtime"></div>
		            </van-col>
		            <van-col span="6" class="rt aui-ftn15 aui-text-red aui-text-right">
		                +<span class="aui-ftn16">{{item.price}}元</span>
		            </van-col>
		        </van-row>
		    </van-list>
		</van-pull-refresh>
    </div>
  </div>
</template>

<script>
  import Invite from '../../service/invite.js'
  import Header from '../components/header.vue'
  export default {
    data () {
      return {
        title: '邀请奖励',
		loading: false,
		invite: {
		    loading: true,
		    finished: false,
		    refreshing: false,
		    items: []
		},
        param: {
            p: 0
        },
        text: '',
		disabled: false
      }
    },
    components: {
      Header
    },
	mounted() {
		this.onLoadData()
		window.addEventListener('scroll', this.handleScroll, true)
	},
	beforeDestroy() {
		window.removeEventListener('scroll', this.handleScroll, true)
	},
    methods: {
		handleScroll () {
			this.disabled = this.utils.handleScroll()
		},
		onLoadData: function() {
				if (this.invite.loading && !this.invite.finished && !this.loading) {
					this.loading = true
					this.param.p++
					var param = {
					  uid: this.$store.state.uid,
					  p: this.param.p,
					  n: 20,
					  isLoading: true,
					  isToken: true
					}
					Invite.fnGetInviteReward(param).then(res => {
						this.loading = false
						// 加载状态结束
						this.invite.loading = false;
						if (res && res.status) {
							this.invite.items = this.invite.items.concat(res.data)
						} else {
							this.invite.finished = true;
							if (this.invite.items.length > 0) this.text = '没有更多了'
						}
					})
				}


		},
		fnLoadMore: function() {
			this.invite.finished = false
			this.invite.loading = true
			this.param.p = 0
			this.text = ''
			this.invite.refreshing = false;
			this.invite.items = [];
			this.onLoadData()
		}
    }
  }
</script>

<style scoped>
  div.record div.list {
      height: 65px;
      padding: 0 20px;
  }
  div.record div.list div.lt {
      padding: 10px 0;
  }
  div.record div.list div.lt div.time {
      padding-top: 5px;
  }
  div.record div.list div.rt {
      line-height: 65px;
  }
</style>
